﻿using System.Collections.Generic;
using System.Linq;
using IOCDemo.Interfaces;

namespace IOCDemo.Services
{
    public class InProcCacheService : ICacheService
    {
        private readonly Dictionary<string, object> cache = new Dictionary<string, object>();
        private readonly ILoggingService loggingService;

        #region Implementation of ICacheService

        public object Get(string key)
        {
            loggingService.Debug("Getting item from cache with key: " + key);
            return cache[key];
        }

        public void Put(string key, object obj)
        {
            loggingService.Debug("Putting item into cache with key: " + key);
            cache.Add(key, obj);
        }

        public void Remove(string key)
        {
            loggingService.Debug("Removing item from cache with key: " + key);
            cache.Remove(key);
        }

        public bool Contains(string key)
        {
            loggingService.Debug("Checking if item exists in cache with key: " + key);
            return cache.Keys.Contains(key);
        }

        #endregion

        public InProcCacheService(ILoggingService loggingService)
        {
            this.loggingService = loggingService;
        }
    }
}